const app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    url: app.apiroot,
    qrcode:"",
  },
  onShow: function(){
    let that = this;
    app.isLogin(function () {
      wx.showLoading({ title: '生成邀请码', mask: true})
      that.setData({
        ucode: app.globalData.loginuser.ucode
      })
      that.getCode();
    });
  },
  //生成二维码
  getCode: function () {
    let that = this;
    var ucode = app.globalData.loginuser.ucode;
    var store_id = app.globalData.loginuser.store_id;
    app.api().Post('openapi/v1/user/miniprogramcode', {
      scene: {ucode: ucode, store_id: store_id},
      page: 'pages/user/index',
      name: 'allwin_' + app.globalData.loginuser.uid
    }, function (result) {
      that.setData({
        qrcode: result.data,
      })
      wx.hideLoading();
    })
  },
  /**
   * 分享按钮
   */
  onShareAppMessage: function (res) {
    let that = this;
    var ucode = app.globalData.loginuser.ucode;
    var store_id = app.globalData.loginuser.store_id;
    return {
      desc: app.appname,
      path: '/pages/user/index?ucode=' + ucode + '&store_id=' + store_id
    }
  },
})